﻿using FairyGUI;

/// <summary>
/// 玩家信息
/// </summary>
public class UIGame_Player_Info
{
    GComponent _comp;
    GamePlayerInfo _playerInfo;
    UIGameHeadpicImage _headpicImg;
    GTextField _nameCtrl;
    GTextField _scoreCtrl;
    GTextField _rscoreCtrl;

    public UIGame_Player_Info(GComponent comp)
    {
        _comp = comp;

        _headpicImg = new UIGameHeadpicImage(_comp.GetChild("头像").asCom, ()=> {
            // TODO 头像被点击
        });
        _nameCtrl = _comp.GetChild("名字").asTextField;
        _scoreCtrl = _comp.GetChild("金币").asTextField;
        _rscoreCtrl = _comp.GetChild("胡息").asTextField;
        SetPlayerInfo(null);
    }

    public void SetPlayerInfo(GamePlayerInfo info)
    {
        _playerInfo = info;

        if (_playerInfo != null)
        {
            _headpicImg.SetHeadpic(_playerInfo.headpic);
            _nameCtrl.text = _playerInfo.name;
            _scoreCtrl.text = "" + _playerInfo.score;
            _rscoreCtrl.text = "胡息：" + _playerInfo.rScore;
            _headpicImg.offlineVisible = !_playerInfo.online;
            _headpicImg.zhuangVisible = _playerInfo.dealer;
        } else
        {
            _nameCtrl.text = "";
            _scoreCtrl.text = "";
            _rscoreCtrl.text = "";
            _headpicImg.offlineVisible = false;
            _headpicImg.zhuangVisible = false;
        }
    }
}
